package com.grocery.service.impl;
import com.grocery.dao.PasswordDao;
import com.grocery.service.IPasswordService;
import com.grocery.util.SYS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PasswordService implements IPasswordService {
    @Autowired
    PasswordDao passwordDao;
    public int changepassword(String oldpassword,String newpassword,String newpasswordagain,int userid) {
        String datapassword = passwordDao.getpassword(userid);
        if(!newpassword.equals(newpasswordagain)){
            return 500;
        }else if(!SYS.checkPassword(oldpassword,datapassword)){
            return 400;
        }else{
            String saltpassword=SYS.digest(newpassword);
            System.out.println(newpassword);
            passwordDao.setpassword(saltpassword,userid);
            return 200;
        }
    }
}
